<?php

namespace App\Admin\Forms;

use App\Jobs\GenerateAgreementJob;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;

class ExpressForm extends Form
{
    use LazyWidget;
    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        $row = $this->payload['row'] ?? null;
        // 保存协议文件
        $agreement = \App\Models\ProjectAgreement::where('id', $row['id'])->first();
        $agreement->express_name = $input['express_name'];
        $agreement->express_code = $input['express_code'];
        $agreement->save();
        return $this->response()->success('上传成功')->refresh();
    }

    /**
     * Build a form here.
     */
    public function form()
    {
        $this->text('express_name')->required();
        $this->text('express_code')->required();
    }

    /**
     * The data of the form.
     *
     * @return array
     */
    public function default()
    {

        $row = $this->payload['row'] ?? null;
        return [
            'express_name'  => $row['express_name'],
            'express_code' => $row['express_code']
        ];
    }
}
